#include "ExpectimaxNegamaxPlayer.h"

ExpectimaxNegamaxPlayer::ExpectimaxNegamaxPlayer(Definitions::PlayerColor playerColor,
		const GameTimer::TimeParams &tp,
		int moves_limit): SenetPlayerExt(playerColor , tp , moves_limit), m_timer(tp)
{
	setName("ExpectimaxNegamaxPlayer");
}

ExpectimaxNegamaxPlayer::~ExpectimaxNegamaxPlayer()
{
}

void ExpectimaxNegamaxPlayer::initGame(int num_squares, int num_pieces, 
								int num_sticks, const SenetBoard &initial_board)
{
	SenetPlayer::initGame(num_squares , num_pieces, num_sticks , initial_board);
	m_algorithm.Init(this , num_sticks);

	// TODO: remove this
	m_overrideStatus = false;
}

#include <iostream>

void ExpectimaxNegamaxPlayer::makeMove(const Board& curBoard, Move &myMove)
{
	SenetMove& move = (SenetMove&) myMove;
	
	//iterative deepening 
	int depth = 1;
	m_timer.startMoveTimer();
	const SenetBoard& kb = (SenetBoard&)curBoard;
	int sticks = kb.getSticksState();

	SenetBoardDraft board(kb, m_size_squares, m_num_pieces);
	try {
		for( ; ; ) //infinite loop - will run until TimeOut
		{
			// TODO: remove this
			if (m_overrideStatus)
			{
				depth = m_depth;
				sticks = m_sticksResult;
				move = m_algorithm.scoreExpectimax(board , depth , m_timer , true , 
					m_myColor , sticks);
				break;
			}

			move = m_algorithm.scoreExpectimax(board , depth , m_timer , true , 
												m_myColor , sticks);
			++depth;
		}
	}
	catch (Exception e)
	{
		int x;
		x = 10;
	}
	std::cout << " *** Heuristics score: " << m_algorithm.m_FinalBoardScore << std::endl;
	std::cout << " *** Depth: " << depth << std::endl;
}

void ExpectimaxNegamaxPlayer::setName(const std::string &s)
{
	m_myName = s;
}